<template>
  <div>
    <h2>用户登录</h2>
    <div>账号：<input type="text" v-model="user"></div>
    <div>密码：<input type="text" v-model="pass"></div>
    <button @click="toHome()">登录</button>
    <!-- <router-link to="/register">还没有账号，去注册</router-link> -->
    <router-link :to="{name:'Register'}">还没有账号，去注册</router-link>
    <!-- <router-link :to="{path:'/register'}">还没有账号，去注册</router-link> -->
  </div>
</template>

<script>
export default {
  data() {
    return {
      user:'admin',
      pass:'123'
    }
  },
    methods:{
        async toHome(){
          const {data} = await this.$api.users.userLogin(this.user,this.pass);
          console.log(data);
          if(data.code){
            localStorage.token = data.token;
            alert('登录成功！');
            this.$router.push('/home');
          }else{
            alert(data.message);
          }
        }
    }
}
</script>

<style>

</style>